/*****************************************
 * We did not test the reminder in this ATD,
 * since it depends on both the deadline of
 * the tasks and the current time.
 * However, the current time changes all the time
 * We will show it during the presentation
 *****************************************/

import java.util.Vector;


public class Controller_ATD {
	
	public static void main (String[] args) throws Exception{
		
		//test setup
		Controller control = new Controller();
		
		//test case 1 (add a task without deadline)
		String input = "add have supper";
		String[] words = input.split(" ");
		control.addTaskWithoutDeadline(input, words);
		Vector<Task> tasks = control.toDoHandling.getData();
		Task task = tasks.get(0);
		if(!task.getDescription().equals("have supper"))
			throw new Exception("test case 1 failed");
		
		java.lang.Thread.sleep(1000);
		
		//test case 2 (add a task with deadline)
		input = "CS2103T presentation /at 3:30pm this Saturday";
		String[] twoSections = input.split("/");
		control.addTaskWithDeadline(twoSections);
		tasks = control.toDoHandling.getData();
		task = tasks.get(1);
		if(!task.getDescription().equals("CS2103T presentation ")||(!task.getTime().equals("15:30:00"))
				||(!task.getDate().equals("Nov 12 2011"))) 
			throw new Exception("test case 2 failed");
		
		java.lang.Thread.sleep(1000);
		
		//test case 3 (add a task using addTask functions)
		input = "add play soccer /at 10pm on Nov 12 2011";
		words = input.split(" ");
		control.addTask(words, input);
		tasks = control.toDoHandling.getData();
		task = tasks.get(2);
		if(!task.getDescription().equals("play soccer ")||(!task.getTime().equals("22:00:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 3 failed");
		
		//test case 4 (add invalid input)
		input = "add /";
		words = input.split(" ");
		control.addTask(words, input);
		tasks = control.toDoHandling.getData();
		int size = tasks.size();
		if(size != 3)
			throw new Exception("test case 4 failed");
		
		//test case 5 (add invalid input)
		input = "add have supper /";
		words = input.split(" ");
		control.addTask(words, input);
		tasks = control.toDoHandling.getData();
		size = tasks.size();
		if(size != 3)
			throw new Exception("test case 5 failed");
		
		//test case 6 (add invalid input)
		input = "add have supper /wrong deadline expression";
		words = input.split(" ");
		control.addTask(words, input);
		tasks = control.toDoHandling.getData();
		size = tasks.size();
		if(size != 3)
			throw new Exception("test case 6 failed");
		
		//test case 7 (add invalid input)
		input = "add /at 10pm";
		words = input.split(" ");
		control.addTask(words, input);
		tasks = control.toDoHandling.getData();
		size = tasks.size();
		if(size != 3)
			throw new Exception("test case 7 failed");
		
		//test case 8 (delete a task)
		task = tasks.get(0);
		String taskID = task.getID();
		Task deletedTask = control.deleteTaskWithValidTaskID('0', taskID);
		if(!deletedTask.getDescription().equals(task.getDescription())
				||(!deletedTask.getTime().equals(task.getTime()))
				||(!deletedTask.getDate().equals(task.getDate())))
			throw new Exception("test case 8 failed");
		control.updateGUI();
		
		//test case 9 ()(delete a task with task id input)
		control.deleteTaskWithTaskIDInput("delete 2", '0');
		tasks = control.toDoHandling.getData();
		task = tasks.get(0);
		if(!task.getDescription().equals("CS2103T presentation ")||(!task.getTime().equals("15:30:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 9 failed");
		
		//test case 10(invalid delete command)
		input = "delete";
		words = input.split(" ");
		control.deleteTaskByTyping(words, input, '0');
		if(!task.getDescription().equals("CS2103T presentation ")||(!task.getTime().equals("15:30:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 10 failed");
		
		//test case 11(invalid delete command)
		input = "delete t";
		words = input.split(" ");
		control.deleteTaskByTyping(words, input, '0');
		if(!task.getDescription().equals("CS2103T presentation ")||(!task.getTime().equals("15:30:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 11 failed");
		control.updateGUI();
		
		//test case 12 (mark as done)
		input = "add play soccer /at 10pm on Nov 12 2011";
		words = input.split(" ");
		control.addTask(words, input);
		input = "mark 2";
		words = input.split(" ");
		control.markTask(input, '0', words);
		tasks = control.doneHandling.getData();
		task = tasks.get(0);
		System.out.println();
		if(!task.getDescription().equals("play soccer ")||(!task.getTime().equals("22:00:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 12 failed");
		control.updateGUI();
		
		//test case 13(edit command)
		input = "edit 1 -a have a rest";
		tasks = control.toDoHandling.getData();
		task = tasks.get(0);
		taskID = task.getID();
		control.editWithTaskID(input, taskID);
		tasks = control.toDoHandling.getData();
		task = tasks.get(0);
		if(!task.getDescription().equals("have a rest")||(!task.getTime().equals("15:30:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 13 failed");
		
		//test case 14(undo)
		input = "undo";
		control.undo();
		tasks = control.toDoHandling.getData();
		task = tasks.get(0);
		System.out.println("+++++++++++++++"+task.getDescription());
		if(!task.getDescription().equals("CS2103T presentation ")||(!task.getTime().equals("15:30:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 14 failed");
		
		//test case 15(redo)
		input = "redo";
		control.redo();
		tasks = control.toDoHandling.getData();
		task = tasks.get(0);
		if(!task.getDescription().equals("have a rest")||(!task.getTime().equals("15:30:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 15 failed");
		
		//test case 16(invalid edit command)
		input = "edit 2 -a have fun";
		tasks = control.toDoHandling.getData();
		task = tasks.get(0);
		taskID = control.gui.getID(2);
		if (taskID!=null)
			throw new Exception("test case 16 failed");
		control.updateGUI();
		
		//test case 17(invalid edit command)
		input = "edit";
		tasks = control.toDoHandling.getData();
		task = tasks.get(0);
		taskID = task.getID();
		control.editWithTaskID(input, taskID);
		if(!task.getDescription().equals("have a rest")||(!task.getTime().equals("15:30:00"))
				||(!task.getDate().equals("Nov 12 2011")))
			throw new Exception("test case 17 failed");
		
		System.out.println("All cases passed");
	}
}
